package com.sgb.kjwl.viewmodel.home;

import android.text.TextUtils;

import com.google.gson.reflect.TypeToken;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.transport.CarriageInfo;
import com.sgb.kjwl.model.entity.transport.CheckStateEntity;
import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.api.NewAPIManager;
import com.sgb.kjwl.model.entity.ProListEntity;
import com.sgb.kjwl.model.entity.transport.CarHallEntity;
import com.sgb.kjwl.model.entity.transport.CarsSourcesEntiity;
import com.sgb.kjwl.model.entity.transport.GoodsInfoEntity;
import com.sgb.kjwl.model.entity.transport.GoodsInfoTypeEntity3;
import com.sgb.kjwl.model.entity.transport.GoodsSourcesEntity;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.swgk.core.base.model.entity.H5ReEntity;
import com.swgk.core.mmkvutil.CacheMarker;
import com.sgb.kjwl.view.ui.fragment.home.LogisticsAcceptForCarriageFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.mmkvutil.MkvUtils;
import com.swgk.core.mmkvutil.DatalUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class LogisticsAcceptForCarriageModel extends BaseViewModel {
    public HomeRepertory repertory;
    private LogisticsAcceptForCarriageFragment fragment;

    private Map<String, Object> map;
    private int mPageIndex;
    public int mPageSize = 3;
    private boolean isCache;

    public LogisticsAcceptForCarriageModel(LogisticsAcceptForCarriageFragment fragment, HomeRepertory repertory) {
        this.fragment = fragment;
        this.repertory = repertory;
    }

    public void getCarrierInfoList(GoodsInfoTypeEntity3 entity3, boolean isLoadMore, int position, int mItemType, boolean isRefresh) {
        mPageIndex = isLoadMore ? mPageIndex + 1 : 1;
        mPageSize = 3;
        map = new HashMap<>();
//        map.put("areaCode", repertory.getAreaCode());
        map.put("page", mPageIndex);
        map.put("limit", mPageSize);
        //经度
        String longitude;
        //纬度
        String latitude;
        if (repertory.getIsLocal()) {
            //经度
            latitude = "".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, "");
            //纬度
            longitude = "".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, "");
        } else {
            //经度
            longitude = repertory.getLongititude();
            //纬度
            latitude = repertory.getLatitude();
        }
        if (null != entity3) {
            if (TextUtils.isEmpty(entity3.getNo())) {
                map.put("carTypeNo", "");
            } else {
                map.put("carTypeNo", entity3.getNo());
            }
        }
        //map.put("latitude", latitude);
        //map.put("longitude", longitude);
        map.put("needVideo", "0");
        if (!(mPageIndex == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        if (fragment.getPosition() == 0 && mPageIndex == 1 && TextUtils.isEmpty(entity3.getNo()) && !isRefresh) {
            Type type = new TypeToken<List<CarsSourcesEntiity>>() {
            }.getType();
            isCache = getCacheData(false, CacheMarker.CARS_INFO_List + mItemType, type, false, mPageIndex);
            if (isCache) {
                return;
            }
        }
       /* APIManager.getInstance().getDriverAPI().getCarrierFilterSourceList2(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<CarsSourcesEntiity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ProListEntity<List<CarsSourcesEntiity>>> data) {
                if (data == null)
                    return;
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if (data.getData() == null) {
                        return;
                    }
                    if (data.getData().getList() == null) {
                        return;
                    }
                    setCacheData(data.getData().getList(), isLoadMore, CacheMarker.CARS_INFO_List + mItemType, false, mPageIndex, isCache);
                }
            }
        });*/
        NewAPIManager.getInstance().getLogisticsAPI().getListCarFindForGoods(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<CarriageInfo>>>>() {
            @Override
            public void onSuccess(BaseEntity<ProListEntity<List<CarriageInfo>>> data) {
                if (data == null)
                    return;
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if (data.getData() == null) {
                        return;
                    }
                    if (data.getData().getList() == null) {
                        return;
                    }
                    setCacheData(data.getData().getList(), isLoadMore, CacheMarker.CARS_INFO_List + mItemType, false, mPageIndex, isCache);
                }
            }
        });

    }

    //找货
    public void getH5Url(String id, int pattern) {
        String detail = "";
        if (pattern == 0) { //承运
            detail = "carrierDetails";
        } else if (pattern == 1) { //货运
            detail = "sourceDetails";
        } else if (pattern == 3) { //找货
            detail = "biddingFindGoodsDetails";
        } else if (pattern == 2) { //找车
            detail = "ownerDetails"; //找车->车辆大厅
        }
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getTeamPriceAPI().getUrlSetting(detail).enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    String url = data.getData().getUrl() + "?id=" + id + "&areaCode=" + repertory.getAreaCode();
                    WebViewX5HostActivity.start(fragment.getActivity(), url);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    // 找货->竞价找货 mode = 1；
    // 货运->货运大厅 mode = 0；
    public void getGoodsList(GoodsInfoTypeEntity3 entity3, int mode, boolean isLoadMore, int position, int mItemType, boolean isRefresh) {
        mPageIndex = isLoadMore ? mPageIndex + 1 : 1;
        mPageSize = 3;
        map = new HashMap<>();
//        map.put("areaCode", repertory.getAreaCode());
        map.put("page", mPageIndex);
        map.put("limit", mPageSize);
        if (entity3.getName().equals("全部")) {
            map.put("goodsModeNo", ""); // 货物类型no
        } else {
            map.put("goodsModeNo", entity3.getNo());
        }
        map.put("pattern", mode);  // v1.5 货源发布模式 0 普通模式  1 竞价模式
        map.put("isApp", 1);
        if (!(mPageIndex == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        if (fragment.getPosition() == 0 && mPageIndex == 1 && entity3.getName().equals("全部") && !isRefresh) {
            Type type = new TypeToken<List<GoodsSourcesEntity>>() {
            }.getType();
            isCache = getCacheData(false, CacheMarker.CARS_INFO_List + mItemType, type, false, mPageIndex);
            if (isCache) {
                return;
            }
        }
        APIManager.getInstance().getDriverAPI().getFilterSourceList(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<GoodsSourcesEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ProListEntity<List<GoodsSourcesEntity>>> data) {
                if (data == null)
                    return;
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if (data.getData() == null) {
                        MToast.showToast(fragment.getActivity(), "暂无数据");
                        return;
                    }
                    if (data.getData().getList() == null) {
                        MToast.showToast(fragment.getActivity(), "暂无数据");
                        return;
                    }
                    if (fragment.getPosition() == 0 && mPageIndex == 1 && entity3.getName().equals("全部") && !isRefresh) {
                        setCacheData(data.getData().getList(), isLoadMore, CacheMarker.CARS_INFO_List + mItemType, false, mPageIndex, isCache);
                    } else {
                        fragment.showList(data.getData().getList(), isLoadMore);
                    }

                } else {
                    MToast.showToast(fragment.getActivity(), data.getState());
                }
            }
        });
    }

    public void getCarsInfoList(GoodsInfoTypeEntity3 entity3, boolean isLoadMore, int position, int mItemType, boolean isRefresh) {
        mPageIndex = isLoadMore ? mPageIndex + 1 : 1;
        mPageSize = 6;
        map = new HashMap<>();
//        map.put("areaCode", repertory.getAreaCode());
        map.put("page", mPageIndex);
        map.put("limit", mPageSize);
        map.put("radius", "");
        map.put("timeSort", 1);
        map.put("pattern", 0);  // v1.5 货源发布模式 0 普通模式  1 竞价模式
        map.put("isApp", 1);
        if (null != entity3) {
            if (TextUtils.isEmpty(entity3.getNo())) {
                List<String> lt = new ArrayList<>();
                map.put("carTypeNos", lt);
            } else {
                List<String> lt = new ArrayList<>();
                lt.add(entity3.getNo());
                map.put("carTypeNos", lt);
            }
        }
        if (!(mPageIndex == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        if (fragment.getPosition() == 0 && entity3.getNo() == "") {
            Type type = new TypeToken<List<CarsSourcesEntiity>>() {
            }.getType();
            if (!isRefresh) {
                isCache = getCacheData(false, CacheMarker.CARS_INFO_List + mItemType, type, false, mPageIndex);
                if (isCache) {
                    return;
                }
            }
        }
        APIManager.getInstance().getDriverAPI().getCarFilterSourceList(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<CarsSourcesEntiity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ProListEntity<List<CarsSourcesEntiity>>> data) {
                if (data == null)
                    return;
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if (data.getData() == null) {
                        return;
                    }
                    if (data.getData().getList() == null) {
                        return;
                    }
                    if (fragment.getPosition() == 0 && entity3.getNo() == "") {
                        setCacheData(data.getData().getList(), isLoadMore, CacheMarker.CARS_INFO_List + mItemType, false, mPageIndex, isCache);
                    } else {
                        fragment.showList(data.getData().getList(), isLoadMore);
                    }
                }
            }
        });
    }

    /**
     * -------------------------------------货车类型 -----------------------------------------------
     */

    public void getCarsType() {
        Type type = new TypeToken<List<GoodsInfoTypeEntity3>>() {
        }.getType();
        boolean isCache = getCacheData(false, CacheMarker.CARS_INFO_TYPE, type, true, 1);
        APIManager.getInstance().getDriverAPI().getCarType("1").enqueue(new ICallBack<BaseEntity<List<GoodsInfoTypeEntity3>>>() {
            @Override
            public void onSuccess(BaseEntity<List<GoodsInfoTypeEntity3>> data) {
                if (data == null) return;

                if (data.getState().equals("ok")) {
                    data.getData().get(0).setName("全部");
                    setCacheData(data.getData(), false, CacheMarker.CARS_INFO_TYPE, true, 1, isCache);
                }
            }
        });
    }

    /**
     * -------------------------------------货物类型 -----------------------------------------------
     */
    public void getGoodsType3() {
       /* Type type = new TypeToken<List<FindPeopleEntity>>() {
        }.getType();
        boolean isCache = getCacheData(false, CacheMarker.GOODS_INFO_TYPE, type, true, 1);*/
        NewAPIManager.getInstance().getLogisticsAPI().getGoodsTypeChooseData().enqueue(new ICallBack<BaseEntity<List<GoodsInfoTypeEntity3>>>() {
            @Override
            public void onSuccess(BaseEntity<List<GoodsInfoTypeEntity3>> data) {
                if (data == null) return;
                if (data.getState().equals("ok")) {
                    data.getData().add(0, new GoodsInfoTypeEntity3("", "全部"));
                    fragment.showGoodsOrCarsTypeData(data.getData());
                }
            }
        });
    }

    /**
     * 是否有缓存
     */
    public <T> boolean getCacheData(boolean isLoadMore, String mType, Type type, boolean isType, int pos) {
        if (fragment.getPosition() == 0 && pos == 1) {
            Object object = DatalUtils.getInstance().getData(MkvUtils.CacheModular, mType, type);
            if (object != null) {
                List<T> list = (List<T>) object;
                if (isType) {
                    fragment.showGoodsOrCarsTypeData(list);
                } else {
                    fragment.showList(list, isLoadMore);
                }
                return true;
            }
        }
        return false;
    }

    /**
     * 是否更新缓存
     */
    public <T> void setCacheData(List<T> dataList, boolean isLoadMore, String mType, boolean isType, int pos, boolean isCache) {
        if (fragment.getPosition() == 0 && pos == 1) {
            String cacheMateialistlHash = DatalUtils.getHashData(MkvUtils.CacheModular, mType);
            //获取从网络请求下来的数据的哈希值
            String mHashNet = DatalUtils.getInstance().strToHashKey(dataList);
            if (!cacheMateialistlHash.equals(mHashNet) || isCache == false) {
                if (isType) {
                    fragment.showGoodsOrCarsTypeData(dataList);
                } else {
                    fragment.showList(dataList, isLoadMore);
                }
                DatalUtils.getInstance().putData(MkvUtils.CacheModular, mType, dataList);
            } else {
                if (isType) {
                } else {
                    fragment.showList(dataList, isLoadMore);
                }
            }
        } else {
            if (isType) {
                fragment.showGoodsOrCarsTypeData(dataList);
            } else {
                fragment.showList(dataList, isLoadMore);
            }
        }
    }

    /**
     * 货源信息新接口
     */
    public void getNewGoodsList(GoodsInfoTypeEntity3 entity3, int pattern, boolean isLoadMore, int position, int mItemType, boolean isRefresh) {
        mPageIndex = isLoadMore ? mPageIndex + 1 : 1;
        if(pattern == 0){
            mPageSize = 6;
        }else {
            mPageSize = 3;
        }
        map = new HashMap<>();
        //经度
        String longitude;
        //纬度
        String latitude;
        if (repertory.getIsLocal()) {
            //经度
            latitude = "".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, "");
            //纬度
            longitude = "".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, "");
        } else {
            //经度
            longitude = repertory.getLongititude();
            //纬度
            latitude = repertory.getLatitude();
        }
        map.put("page", mPageIndex);
        map.put("limit", mPageSize);
        if (entity3.getName().equals("全部")) {
            map.put("goodsTypeNo", ""); // 货物类型no
        } else {
            map.put("goodsTypeNo", entity3.getNo());
        }
        map.put("pattern", pattern);
        //map.put("latitude", latitude);
        //map.put("longitude", longitude);
        if (!(mPageIndex == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        if (fragment.getPosition() == 0 && mPageIndex == 1 && entity3.getName().equals("全部") && !isRefresh) {
            Type type = new TypeToken<List<GoodsSourcesEntity>>() {
            }.getType();
            if (!isRefresh) {
                isCache = getCacheData(false, CacheMarker.CARS_INFO_List + mItemType, type, false, mPageIndex);
                if (isCache) {
                    return;
                }
            }
        }

        NewAPIManager.getInstance().getLogisticsAPI().getFilterSourceList(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<GoodsInfoEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ProListEntity<List<GoodsInfoEntity>>> data) {
                if (data == null)
                    return;
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if (data.getData() == null) {
                        MToast.showToast(fragment.getActivity(), "暂无数据");
                        return;
                    }
                    if (data.getData().getList() == null) {
                        MToast.showToast(fragment.getActivity(), "暂无数据");
                        return;
                    }
                    setCacheData(data.getData().getList(), isLoadMore, CacheMarker.CARS_INFO_List + mItemType, false, mPageIndex, isCache);


                } else {
                    MToast.showToast(fragment.getActivity(), data.getState());
                }
            }
        });
//        APIManager.getInstance().getDriverAPI().getFilterGoodsSourceHall(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<GoodsInfoEntity>>>>() {
//            @Override
//            public void onSuccess(BaseEntity<ProListEntity<List<GoodsInfoEntity>>> data) {
//
//            }
//        });
    }

    /**
     * 货车信息新街口
     */
    public void getCarList(GoodsInfoTypeEntity3 entity3, int mode, boolean isLoadMore, int position, int mItemType, boolean isRefresh) {
        mPageIndex = isLoadMore ? mPageIndex + 1 : 1;
        mPageSize = 6;
        map = new HashMap<>();
        //经度
        String longitude;
        //纬度
        String latitude;
        if (repertory.getIsLocal()) {
            //经度
            latitude = "".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, "");
            //纬度
            longitude = "".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, "");
        } else {
            //经度
            longitude = repertory.getLongititude();
            //纬度
            latitude = repertory.getLatitude();
        }

        if (!(mPageIndex == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        if (fragment.getPosition() == 0 && mPageIndex == 1 && entity3.getName().equals("全部") && !isRefresh) {
            Type type = new TypeToken<List<CarHallEntity>>() {
            }.getType();
            isCache = getCacheData(false, CacheMarker.CARS_INFO_List + mItemType, type, false, mPageIndex);
            if (isCache) {
                return;
            }
        }

        Map map = new HashMap();
        map.put("page", mPageIndex);
        map.put("limit", mPageSize);
        map.put("needVideo", 0);
        //当前查找经纬度
        //map.put("ipLongitude", longitude);
        //map.put("ipLatitude", latitude);
        if (!TextUtils.isEmpty(entity3.getNo())) {
            map.put("carTypeNos", entity3.getNo());
        } else {
            map.put("carTypeNos", "");
        }
        map.put("provinceNo", "");
        map.put("cityNo", "");
        map.put("districtNo", "");
        map.put("shipmentTime", null);
        map.put("shipmentEndTime", null);

        NewAPIManager.getInstance().getLogisticsAPI().getCarToMainPage(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<CarHallEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ProListEntity<List<CarHallEntity>>> data) {
                if (data == null)
                    return;
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if (data.getData() == null) {
                        MToast.showToast(fragment.getActivity(), "暂无数据");
                        return;
                    }
                    if (data.getData().getList() == null) {
                        MToast.showToast(fragment.getActivity(), "暂无数据");
                        return;
                    }
                    if (fragment.getPosition() == 0 && mPageIndex == 1 && entity3.getName().equals("全部")) {
                        setCacheData(data.getData().getList(), isLoadMore, CacheMarker.CARS_INFO_List + mItemType, false, mPageIndex, isCache);
                    } else {
                        fragment.showList(data.getData().getList(), isLoadMore);
                    }
                } else {
                    MToast.showToast(fragment.getActivity(), data.getState());
                }
            }
        });
//        NewAPIManager.getInstance().getLogisticsAPI().getCarList(
//                mPageIndex + "", mPageSize + "",
//                "", "0", "1",
//                longitude, latitude, "", "", "",
//                "", entity3.getNo(), "",
//                0, null, null)
//                .enqueue(new ICallBack<BaseEntity<ProListEntity<List<CarHallEntity>>>>() {
//                    @Override
//                    public void onSuccess(BaseEntity<ProListEntity<List<CarHallEntity>>> data) {
//                        if (data == null)
//                            return;
//                        if (data.getState().equals(APIManager.RESPONSE_OK)) {
//                            if (data.getData() == null) {
//                                MToast.showToast(fragment.getActivity(), "暂无数据");
//                                return;
//                            }
//                            if (data.getData().getList() == null) {
//                                MToast.showToast(fragment.getActivity(), "暂无数据");
//                                return;
//                            }
//                            if (fragment.getPosition() == 0 && mPageIndex == 1 && entity3.getName().equals("全部")) {
//                                setCacheData(data.getData().getList(), isLoadMore, CacheMarker.CARS_INFO_List + mItemType, false, mPageIndex, isCache);
//                            } else {
//                                fragment.showList(data.getData().getList(), isLoadMore);
//                            }
//                        } else {
//                            MToast.showToast(fragment.getActivity(), data.getState());
//                        }
//                    }
//                });
    }

    public void getFilterSourceList3(int type, String goodsModeNo, int pattern, boolean isLoadMore, boolean isRefresh) {
        mPageIndex = isLoadMore ? mPageIndex + 1 : 1;
        mPageSize = 6;
        map = new HashMap<>();
        //经度
        String longitude;
        //纬度
        String latitude;
        if (repertory.getIsLocal()) {
            //经度
            latitude = "".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, ""))
                    ? repertory.getLatitude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LATITUDE_ID, "");
            //纬度
            longitude = "".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, ""))
                    ? repertory.getLongititude() : SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LONGITUDE_ID, "");
        } else {
            //经度
            longitude = repertory.getLongititude();
            //纬度
            latitude = repertory.getLatitude();
        }
        // map.put("areaCode", repertory.getAreaCode());
        map.put("page", mPageIndex);
        map.put("limit", mPageSize);
        map.put("latitude", latitude);
        map.put("longitude", longitude);
        map.put("goodsModeNo", goodsModeNo); // 货物类型no
        map.put("minWeight", 0);
        map.put("maxWeight", 0);
        map.put("maxVolume", 0);
        map.put("needVideo", "0");
        map.put("shipmentEndTime", "");
        map.put("carLenNosList", new ArrayList<>());
        map.put("carTypeNosList", new ArrayList<>());
        map.put("provinceNo", "");
        map.put("cityNo", "");
        map.put("districtNo", "");
        map.put("destProvinceNo", "");
        map.put("isApp", 1);
        map.put("pattern", pattern == 0 ? 0 : 1);
        if (pattern == 0) {
            NewAPIManager.getInstance().getLogisticsAPI().getFilterGoodsSourceList(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<GoodsInfoEntity>>>>() {
                @Override
                public void onSuccess(BaseEntity<ProListEntity<List<GoodsInfoEntity>>> data) {
                    if (type == 1) {
                        fragment.showList(data.getData().getList(), isLoadMore);
                    }
                }
            });
        } else {
            NewAPIManager.getInstance().getLogisticsAPI().getCompeteFindGoods(map).enqueue(new ICallBack<BaseEntity<ProListEntity<List<GoodsInfoEntity>>>>() {
                @Override
                public void onSuccess(BaseEntity<ProListEntity<List<GoodsInfoEntity>>> data) {

                }
            });
        }
    }

    public void goodsSourceStatusCheck(String no, int pattern) {
        NewAPIManager.getInstance().getLogisticsAPI().goodsSourceStatusCheck(no).enqueue(new Callback<BaseEntity<CheckStateEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<CheckStateEntity>> call, Response<BaseEntity<CheckStateEntity>> response) {
                if (response.body() == null) return;

                if (response.body().getState().equals("ok")) {
                    fragment.checkGoodsState(no, pattern, response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<CheckStateEntity>> call, Throwable t) {

            }
        });
    }
}
